package com.aliyun.heiyu.powermaster.server.dao.entity;

import com.google.common.base.Strings;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.List;

public class PowerCappingPolicyDto implements Serializable {
    private Byte applyType;
    private String applyTo;
    private Byte powerReductionPolicy;
    private List<PowerCappingPolicyDto.PowerTriggerPolicy> triggerPolicy;
    private PowerCappingPolicyDto.PowerExitPolicy exitPolicy;
    private static final long serialVersionUID = 1L;

    public PowerCappingPolicyDto() {
    }

    public Byte getApplyType() {
        return this.applyType;
    }

    public void setApplyType(Byte applyType) {
        this.applyType = applyType;
    }

    public String getApplyTo() {
        return this.applyTo;
    }

    public void setApplyTo(String applyTo) {
        this.applyTo = applyTo == null ? null : applyTo.trim();
    }

    public Byte getPowerReductionPolicy() {
        return this.powerReductionPolicy;
    }

    public void setPowerReductionPolicy(Byte powerReductionPolicy) {
        this.powerReductionPolicy = powerReductionPolicy;
    }

    public List<PowerTriggerPolicy> getTriggerPolicy() {
        return this.triggerPolicy;
    }

    public void setTriggerPolicy(String triggerPolicyJson) {
        if (Strings.isNullOrEmpty(triggerPolicyJson)) {
            this.triggerPolicy = null;
        } else {
            this.triggerPolicy = com.alibaba.fastjson.JSONArray.parseArray(triggerPolicyJson,PowerCappingPolicyDto.PowerTriggerPolicy.class);
            //this.triggerPolicy = Json2.parseToArray(triggerPolicyJson, PowerCappingPolicyDto.PowerTriggerPolicy.class);
        }

    }

    public PowerCappingPolicyDto.PowerExitPolicy getExitPolicy() {
        return this.exitPolicy;
    }

    public void setExitPolicy(String exitPolicyJson) {
        if (Strings.isNullOrEmpty(exitPolicyJson)) {
            this.exitPolicy = null;
        } else {
            this.exitPolicy = com.alibaba.fastjson.JSONArray.parseObject(exitPolicyJson,PowerCappingPolicyDto.PowerExitPolicy.class);
            //this.exitPolicy = (PowerCappingPolicyDto.PowerExitPolicy)Json2.fromJson(exitPolicyJson, PowerCappingPolicyDto.PowerExitPolicy.class);
        }

    }

    public static class PowerExitPolicy {
        private Float exitThreshold;
        private Integer coolDownPeriod;

        public PowerExitPolicy() {
        }

        public Float getExitThreshold() {
            return this.exitThreshold;
        }

        public void setExitThreshold(Float exitThreshold) {
            this.exitThreshold = exitThreshold;
        }

        public Integer getCoolDownPeriod() {
            return this.coolDownPeriod;
        }

        public void setCoolDownPeriod(Integer coolDownPeriod) {
            this.coolDownPeriod = coolDownPeriod;
        }
    }

    public static class PowerTriggerPolicy implements Comparable<PowerCappingPolicyDto.PowerTriggerPolicy> {
        private Float threshold;
        private Integer strategy;
        private Integer period;

        public PowerTriggerPolicy() {
        }

        public Float getThreshold() {
            return this.threshold;
        }

        public void setThreshold(Float threshold) {
            this.threshold = threshold;
        }

        public Integer getStrategy() {
            return this.strategy;
        }

        public void setStrategy(Integer strategy) {
            this.strategy = strategy;
        }

        public Integer getPeriod() {
            return this.period;
        }

        public void setPeriod(Integer period) {
            this.period = period;
        }

        public int compareTo(PowerCappingPolicyDto.PowerTriggerPolicy o) {
            int num = this.strategy - o.getStrategy();
            return num;
        }
    }
}
